//
//  ViewController.m
//  10-homework
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "HandleData.h"
#import "Data.h"
#import "CycleImage.h"
#import "List.h"
#import "PinYouAds.h"
#import "CustomTableViewCell.h"
#import "NewsTableViewCell.h"
@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSDictionary *soureDictionary;
@property (nonatomic, strong) Data *data;
@property (nonatomic, strong) CycleImage *cycleImage;
@property (nonatomic, strong) List *list;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"pool"];
    [_tableView registerClass:[NewsTableViewCell class] forCellReuseIdentifier:@"pool1"];
    [self handleData];
}

- (void)handleData {
    self.soureDictionary = [NSDictionary dictionary];
    _soureDictionary = [HandleData handleDataWithPathSoure:@"YiChe" type:@"plist"];
    NSLog(@"%@", _soureDictionary);
    NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
    for (NSString *key in _soureDictionary) {
        id soureData = [_soureDictionary objectForKey:key];
        [tempDic setObject:soureData forKey:@"data"];
    }
    // Data类中字典赋值
    self.data = [[Data alloc] initWithDictionary:tempDic];
    
    NSDictionary *dic = [_soureDictionary objectForKey:@"data"];
    NSArray *tempArray1 = [dic objectForKey:@"cycleImage"];
    // cycleImage(Array)赋值
    self.cycleImage = [[CycleImage alloc] initWithCycleImageArray:tempArray1];
    // fouces 先不创建对象
    NSArray *tempArray2 = [dic objectForKey:@"list"];
    // list(array)赋值
    self.list = [[List alloc] initWithListArray:tempArray2];
    
    
}







- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    
    return _list.listArray.count + 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
       CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
        return cell;
    } else {
        NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool1"];
        return cell;
    }
    
}








@end
